import {observable, /*toJS*/} from 'mobx';
import {Tools,Bubble} from 'weaver-mobile';
import { RouteLayout,Form } from 'weaver-mobile-page';
import * as API from '../../api/home/more';
import {toJS} from 'mobx'

const getLabel = Tools.getLabel;


export default class MoreStore {
    @observable loading = false;
    @observable hasRight = '';
    @observable baseRoute = '';

    @observable toAddApplicationRoute = new RouteLayout.Store({id:'addApplication',route:'/home/toMore'})

    @observable oftenFunction = [];
    @observable moreFunction = [];

    @observable addOftenFunction = [];
    @observable addMoreFunction = [];

    initData = (value={}) =>{
        this.getThreePartiesMore(value);
    }

    //获取三方
    getThreePartiesMore = (value) =>{
        this.loading = true;
        API.getThreePartiesMore(value).then( res=>{
            const {status} = res;
            if(status === '1'){
                if(value.op == '0'){
                    this.addOftenFunction = res.oftenFunction;
                    this.addMoreFunction = res.moreFunction;
                }else if(value.op == '1'){//更多应用 展示页面
                    this.oftenFunction = res.oftenFunction;
                    this.moreFunction = res.moreFunction;
                }
                
                
            }else{
                Bubble.error(res.errorInfo)
            }
            this.loading = false;
        }) 

    }

    //保存 三方
    saveThreeParties = (value={},callBack) =>{
        this.loading = true;
        API.saveThreeParties(value).then( res=>{
            const {status} = res;
            if(status === '1'){
                callBack && callBack();
            }else{
                Bubble.error(res.errorInfo)
            }
            this.loading = false;
        }) 

    }


    //根据传出来的数据拼接 key - value
    joinObj = (data,k) =>{
        let _obj = {};
        data.map( item =>{
            _obj[item.key] = item[k]
        })
      
        return _obj
    }

    //清除more 的数据
    clearMoreData = () =>{
        this.oftenFunction = [];
        this.moreFunction = [];
    }

    setAddOftenFunction = (value) =>{
        this.addOftenFunction = value;
    }
    
}